
// -----------二叉树遍历转换
type Tree = {
    value: number;
    left?: Tree;
    right?: Tree;
}
const tree: Tree = {
    value: 1,
    left: {
        value: 2,
        right: { value: 5, left: { value: 6 } },
        left: { value: 4 }
    },
    right: { value: 3 }
};

function treePath(root: Tree): string[] {
    let list: string[] = [];
    function path(node: Tree, target: string) {
        target = `${target}${target === '' ? '' : '>'}${node.value}`;
        if (node.left) {
            path(node.left, target);
        }
        if (node.right) {
            path(node.right, target);
        }
        if (node.left === undefined && node.right === undefined) {
            list.push(target);
        }
    }
    path(root, '');
    return list;
}

// ---------笛卡尔积数组(就是个多维数组遍历,js一般就二维)
function product(xList: number[], yList: number[]): [number, number][] {
    let result: [number, number][] = [];
    for (let i = 0; i < xList.length; i++) {
        for (let j = 0; j < yList.length; j++) {
            result.push([xList[i], yList[j]]);
        }
    }
    return result;
}
console.log(product([1, 3], [2, 4, 7]));